package com.igeek.clud_system.controller;

import com.igeek.clud_system.common.Const;
import com.igeek.clud_system.entity.ActivityScoreValue;
import com.igeek.clud_system.entity.PersonActivity;
import com.igeek.clud_system.entity.Student;
import com.igeek.clud_system.service.ActivityScoreService;
import com.igeek.clud_system.service.ActivityService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ActivityScoreController {
    @Autowired
    private ActivityScoreService activityScoreService;
    @Autowired
    private ActivityService activityService;
    @GetMapping("activityScore")
    public List<PersonActivity> findActivityScoreValue(HttpSession session){
        System.out.println("111111111111111111111111111111111111111111111111111111");
        Student student=(Student) session.getAttribute(Const.LOGIN_USER);
        List<ActivityScoreValue> activityScoreValues=activityScoreService.findActicityScore(student.getStudentId());
        List<PersonActivity> personActivities=new ArrayList<>();
        for (ActivityScoreValue activityScoreValue : activityScoreValues) {
            System.out.println(activityScoreValue.getDate()+"/"+activityScoreValue.getScore());
            PersonActivity p=new PersonActivity();
            p.setActivityId(activityScoreValue.getActivityId());
            p.setStudentId(activityScoreValue.getStudentId());
            p.setScore(activityScoreValue.getScore());
            p.setDate(activityScoreValue.getDate());
            p.setActivityName(activityService.findActivityById(activityScoreValue.getActivityId()).getActivityName());
            personActivities.add(p);

        }

        return personActivities;
    }
}
